{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e61770ae",
   "metadata": {},
   "source": [
    "# layers\n",
    "\n",
    "网络层\n",
    "\n",
    "tf=2.9.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "21053264",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2.9.1'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "tf.__version__"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2f28994a",
   "metadata": {},
   "source": [
    "## 通常层"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e6f3662a",
   "metadata": {},
   "source": [
    "### Activation 激活函数层\n",
    "\n",
    "```python\n",
    "tf.keras.layers.Activation(*args, **kwargs)\n",
    "```\n",
    "\n",
    "**调用形式（例如 relu）**\n",
    "- tf.keras.layers.Activation('relu')\n",
    "- tf.keras.layers.Activation(tf.nn.relu) "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cc950c52",
   "metadata": {},
   "source": [
    "### ActivityRegularization  正则化\n",
    "\n",
    "添加对于input activity(输入与权值相乘后的值)的正则化损失.\n",
    "\n",
    "```python\n",
    "tf.keras.layers.ActivityRegularization(*args, **kwargs)\n",
    "```\n",
    "\n",
    "**调用形式**\n",
    "- tf.keras.layers.ActivityRegularization(l1=0.0, l2=0.0)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "724a97fc",
   "metadata": {},
   "source": [
    "## Add 相加\n",
    "\n",
    "```python\n",
    "\n",
    "tf.keras.layers.Add(*args, **kwargs)\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "2e4ec6a6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2, 3, 4)\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "input_shape = (2, 3, 4)\n",
    "x1 = tf.random.normal(input_shape)\n",
    "x2 = tf.random.normal(input_shape)\n",
    "\n",
    "# equivalent to `added = tf.keras.layers.add([x1, x2])`\n",
    "y = tf.keras.layers.Add()([x1, x2]) \n",
    "print(y.shape)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a232e823",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "03886bd8",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8a7ca97f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
